export const globalData = {}

/**
 * 设置全局数据
 * @param {Object} key
 * @param {Object} val
 */
export function setGlobalData (key, val) {
  globalData.key = val
}

/**
 * 获取全局数据
 * @param {Object} key
 */
export function getGlobalData (key) {
  return globalData.key
}

/**
 * 获取状态栏的高度
 */
export const statusBarHeight = uni.getSystemInfoSync().statusBarHeight;


/**
 * 获取菜单按钮（右上角胶囊按钮）上边界坐标
 */
const menuBtnTop = uni.getMenuButtonBoundingClientRect().top; //获取菜单按钮（右上角胶囊按钮）上边界坐标
const gap = (menuBtnTop-statusBarHeight)*2; //获取状态栏与菜单按钮（右上角胶囊按钮）之间的间隔距离*2
export const menuHeight = uni.getMenuButtonBoundingClientRect().height +  gap; //获取菜单按钮（右上角胶囊按钮）高度 + gap

/**
 * 获取navBar的高度
 */
export const navBarHeight = statusBarHeight + menuHeight; 

/**
 * 封装接口请求
 */
export const Request = (url,data={},header={"content-type":"application/json"},method="POST") => {
	return new Promise((resolve,reject)=>{
		uni.request({
			url: url,
			data: data,
			header: header,
			method: method,
			success: function(res){
				resolve(res);
			},
			fail: function(res){
				reject(res);
			}
		})
	})
}

//获取某月的天数
export function getMonthDay(year,month){
    var date = new Date(year,month,0);
    return date.getDate();
}

//周数改为文本表达
export function weekNumToText(weekNum){
    switch(weekNum){
        case 0:
            return "周日";
        case 1:
            return "周一";
        case 2:
            return "周二";
        case 3:
            return "周三";
        case 4:
            return "周四";
        case 5:
            return "周五";
        case 6:
            return "周六";
        default:
            return "error";
    }
}

//组合字符串型的年月日
export function combineDate(year,month,day){
    var fmt_month;
    var fmt_day;
    if(month<10){
        fmt_month = "0" + month;
    }else{
        fmt_month = month
    }

    if(day<10){
        fmt_day = "0" + day;
    }else{
        fmt_day = day;
    }

    let fmt_date = year+"/"+fmt_month+"/"+fmt_day;

    return fmt_date;


}